let productList = [
  {
    'id': 1,
    'name': '花知晓【双十一】贝壳珍珠礼盒精华蜜唇釉腮红眼影盘送女友礼物 【热销】珍贝绮彩',
    'img': 'imgs/ic_1.png',
    'price': 199
  },
  {
    'id': 2,
    'name': '美宝莲FITME小磨方粉饼哑光散粉定妆补妆控油光 110自然偏白生日礼物女',
    'img': 'imgs/ic_2.png',
    'price': 499
  },
  {
    'id': 3,
    'name': '古驰口红香水礼盒套装节日生日礼物女士实用高档大牌礼物 热款：绒雾505+花悦女士香水5ml',
    'img': 'imgs/ic_3.png',
    'price': 275
  },
  {
    'id': 4,
    'name': 'HUAWEI MatePad Pro 13.2英寸2025柔光版WiFi 12GB+256GB 砚黑',
    'img': 'imgs/ic_4.png',
    'price': 5699
  },
  {
    'id': 5,
    'name': 'SK-II护肤精华露神仙水套装SK2套装礼盒skll护肤精华 神仙水75ml全晶透随心装',
    'img': 'imgs/ic_5.png',
    'price':559
  },
  {
    'id': 6,
    'name': 'Matebook E Go',
    'img': 'imgs/ic_6.png',
    'price': 6288
  }
];

// 获取所选商品详细信息
let urlSearchParams = new URLSearchParams(window.location.search);
let productIndex = urlSearchParams.get('index');
let productDetail = productList[productIndex];
productDetail.sku = '颜色，8GB+128GB，七天无理由退换';
let swiperStr = '<img alt="" class="showing" src="' + productDetail.img + '" />';
for (let i = 0; i < 3; i++) {
  swiperStr += '<img alt="" src="imgs/ic_' + ((productDetail.id + i) % 6 + 1) + '.png" />'
}
swiperStr += '<div id="dot" >1/4</div>';
document.getElementById('swiper').innerHTML = swiperStr;
document.getElementById('price').innerHTML = '<span>¥ </span>' + productDetail.price;
document.getElementById('product-name').innerHTML = productDetail.name;

let currentIndex = 0;
let images = document.querySelectorAll('#swiper img');

function showNext() {
  var currentImg = document.querySelector('.showing');
  if (currentImg) {
    currentImg.classList.remove('showing');

    currentIndex += 1;
    if (currentIndex >= images.length) {
      currentIndex = 0;
    }
    var dot = document.querySelector('#dot');
    dot.innerHTML = (currentIndex + 1) + '/4';
    images[currentIndex].classList.add('showing');
  } else {
    images[0].classList.add('showing');
  }
}

setInterval(showNext, 2000);

// 调用应用端函数跳转至商品结算页面
function orderConfirm() {
  arkTSFunObj.jumpOrderConfirm(JSON.stringify(productDetail));
}
